import {createRouter, createWebHistory} from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import testView from "@/views/testView.vue";
import  IndexView from "@/views/index/indexView/IndexView.vue";
import  HealthCenter from "@/views/index/healthCenter/HealthCenter.vue";
// import Editingdata from "@/components/gerenzhongxin/Head/Headimage/bianjiziliao/Editingdara.vue";
import HeadModify from "@/components/gerenzhongxin/Head/Headimage/bianjiziliao/touxiangxiugai/HeadModify.vue";
import Modifyname from "@/components/gerenzhongxin/Head/Headimage/bianjiziliao/mingchengxiugai/Modifyname.vue";
import Myinformation from "@/components/gerenzhongxin/fourPart/message/Myinformation.vue";
import  SearchView from "@/views/index/search/SearchView.vue";
import  SearchResults from "@/views/index/search/SearchResults.vue";
import  SearchTeacher from "@/views/index/search/SearchTeacher.vue";
import  SearchText from "@/views/index/search/SearchText.vue";
import  AllTeacher from "@/views/index/teacher/AllTeacher.vue";
import TeacherDetail from "@/views/index/teacher/TeacherDetail.vue";
import AgreementView from "@/views/index/teacher/AgreementView.vue";
import TextDetail from "@/views/index/text/TextDetail.vue";
import CollectionPaga from "@/components/gerenzhongxin/fourPart/Collection/CollectionPaga.vue";
import SetUp from "@/components/gerenzhongxin/fourPart/Set up/SetUp.vue";
import phoneModify from "@/components/gerenzhongxin/fourPart/Set up/phone/phoneModify.vue";
import EvaluaTion from "@/components/gerenzhongxin/Content/Evaluationrecord/evaluation/Evaluation.vue";
import EvaluationResults from "@/components/gerenzhongxin/Content/Evaluationrecord/evaluation/Evaluationresults/Evaluationresults.vue";
import appointment from "@/components/gerenzhongxin/Content/Myconsultation/appointment/Appointment.vue";
import consultation from "@/components/gerenzhongxin/Content/Myappointment/Consultation/Consultation.vue";
import phoneNumber from "@/components/gerenzhongxin/fourPart/Set up/phone/phone number/phoneNumber.vue";
import passWord from "@/components/gerenzhongxin/fourPart/Set up/password/Password.vue";
import dengLu from "@/components/denglu/Login.vue";
import BookingDetails from "@/components/gerenzhongxin/Content/Myconsultation/appointment/Bookingdetails/BookingDetails.vue";
import AllText from "@/views/index/text/AllText.vue";
import TreeHole from "@/views/treeHole/TreeHole.vue";
import PublishHole from "@/views/treeHole/PublishHole.vue";
import DetailHole from "@/views/treeHole/DetailHole.vue";
import MakeAppointment from "@/views/reservation/MakeAppointment.vue";
import PersonalCenter from "@/views/personCenter/PersonalCenter.vue";
import PsychologicalEvaluation from "@/views/PsychologicalEvaluation.vue";
import PsychoLogical from "@/components/PsychologicalEvaluation/PsychoLogical.vue";
import canCellation from "@/components/gerenzhongxin/Content/Myconsultation/appointment/Bookingdetails/Reasonscancellation/Cancellation.vue";
import ConsultationDetails from "@/components/gerenzhongxin/Content/Myappointment/Consultation/ConsultationDetails/Consultationdetails.vue";
import Editingdara from "@/components/gerenzhongxin/Head/Headimage/bianjiziliao/Editingdara.vue";
import Messagedetails from "@/components/gerenzhongxin/fourPart/message/Messagedetails/Messagedetails.vue";
import {Tokens} from "@/stores/token";
import NewAppointment from "@/views/NewAppointment.vue";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
      // 拨号
      // { path: '/dial', component: DialPage },
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (About.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import('../views/AboutView.vue')
    // },
    //   路由重定向
      {
          path:'/',
          redirect:'/index'
      },
      // 个人中心
    {
      path:'/gerenzhongxin',
      component:PersonalCenter
    }
    ,
    //   // 编辑资料
    {
      path:'/bianjiziliao',
      component:Editingdara
    },
      // 修改头像
    {
      path:'/xiugaitouxiang',
      component:HeadModify
    },
      // 修改昵称
    {
      path:'/xiugaimingcheng',
      component:Modifyname
    },
    // 我的信息
    {
      path:'/wodexinxi',
      component:Myinformation
    },
      // 我的收藏
    {
      path:'/wodeshoucang',
      component: CollectionPaga
    },
      // 设置
    {
      path:'/shezhi',
      component: SetUp
    },
      // 手机修改
    {
      path:'/shoujixiugai',
      component: phoneModify
    },
      // 测评记录
    {
      path:'/cepingjilu',
      component: EvaluaTion
    },
      // 测评结果
    {
      path:'/cepingjieguo',
      component: EvaluationResults
    },
      // 我的预约
    {
      path:'/wodeyuyue',
      component: appointment
    },
      // 我的咨询
    {
      path:'/wodezixun',
      component: consultation
    },
      // 更换手机号
    {
      path:'/genghuanshoujihao',
      component: phoneNumber
    },
      // 修改密码
    {
      path:'/xiugaimima',
      component: passWord
    },
      // 登录
    {
      path:'/denglu',
      component:dengLu
    },
    {
        // 预约详情
      path:'/yuyuexiangqing',
      component:BookingDetails
    },
      // 取消评论
      {
          path:'/canCellation',
          component:canCellation
      },
      //心理测评
      {
          path:'/PsychologicalEvaluation',
          component:PsychologicalEvaluation
      },
      //咨询详情
      {
          path:'/ConsultationDetails',
          component:ConsultationDetails
      },
      //消息详情
      {
          path:'/Messagedetails',
          component:Messagedetails
      },
      //测试
      {
          path:'/PsychoLogical',
          component:PsychoLogical
      },
        // 主页

        {
            path: '/index',
            component: IndexView
        },
        // 健康中心介绍
        {

            path: '/health',
            component: HealthCenter
        },
        // 测试用例
        {
            path: '/test',
            component: testView
        },
        // 搜索页面
        {
            path: '/search',
            component: SearchView
        },
        // 搜索结果
        {
            path: '/result/:keyword',
            component: SearchResults,
            name:'searchResult'
        },
        //     搜索咨询师
        {
            path: '/searchTeacher',
            component: SearchTeacher
        },
        //     搜索文章
        {
            path: '/searchText',
            component: SearchText
        },
        //    更多咨询师
        {
            path: '/allTeacher',
            component: AllTeacher
        },
        //     咨询师详情
        {
            path: '/teacherDetail',
            component: TeacherDetail
        },
        //     预约协议
        {
            path: '/agree',
            component: AgreementView
        },
        //     文章详情
        {
            path: '/textDetail',
            component: TextDetail
        },
        // 更多文章
        {
            path: '/allText',
            component: AllText
        },
        //     树洞主页面
        {
            path: '/tree',
            component: TreeHole,
            meta:{
                isLogin:true
            }
        },
        // 发布树洞
        {
            path: '/publishHole',
            component: PublishHole
        },
        //  树洞详情
        {
            path: '/detailHole',
            component: DetailHole
        },
        //     预约主页
        {
            path:'/makeAppointment',
            component:MakeAppointment
        },
      {
          path:'/newAppointment',
          component:NewAppointment
      }
    ]

})



//路由守卫（全局）
// 1. 接口返回值去判断，接口返回的状态码是401和403，代表没有权限，在响应拦截器里跳转到登录界面，带上returnUrl， 登录成功之后还回到这个页面
// 2. 路由里的meta属性，携带一些路由信息，可以给路由配上这个属性，然后设置一个固定参数

// 没守住版
router.beforeEach((to, from, next) => {
    const store = Tokens()
    const isToken = store.getToken() != '' //判断pinia 里的token是否存在
    if (to.path != '/denglu' && !isToken) {
        next({path: '/denglu'});
    } else {
        next();
    }
})

export default router
